package com.example.conventor;

import com.example.constant.UserStatus1;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;

public class UserStatusEnumDeserializer extends JsonDeserializer<UserStatus1> {
    @Override
    public UserStatus1 deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
            throws IOException {
        final String source = jsonParser.getText();

        System.out.println("正在执行UserStatus的deserialize方法:"+source);
        int i = Integer.parseInt(source);
        UserStatus1[] values = UserStatus1.values();
        for (UserStatus1 value : values) {
            if (i==(value.getValue())) {
                System.out.println("已匹配到正确的UserStatus数据并返回:"+value);
                return value;
            }
        }
        throw new RuntimeException("无效枚举值");
    }
}

